package com.mb.ext.core.dao.impl.group;

import javax.persistence.NoResultException;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.mb.ext.core.dao.AbstractBaseDAO;
import com.mb.ext.core.dao.group.GroupBuyDefMerchantDAO;
import com.mb.ext.core.entity.group.GroupBuyDefMerchantEntity;
import com.mb.framework.exception.DAOException;
import com.mb.framework.util.log.LogHelper;

@Repository("groupBuyDefMerchantDAO")
@Qualifier("groupBuyDefMerchantDAO")
public class GroupBuyDefMerchantDAOImpl extends AbstractBaseDAO<GroupBuyDefMerchantEntity> implements GroupBuyDefMerchantDAO {
	private final LogHelper logger = LogHelper.getInstance(this.getClass().getName());

	/**
	 * Initializing Entity.
	 */
	public GroupBuyDefMerchantDAOImpl() {
		super();
		this.setEntityClass(GroupBuyDefMerchantEntity.class);
	}

	@Override
	public void addGroupBuy(GroupBuyDefMerchantEntity groupBuyDefMerchantEntity) throws DAOException {

		this.save(groupBuyDefMerchantEntity);

	}

	@Override
	public void updateGroupBuy(GroupBuyDefMerchantEntity groupBuyDefMerchantEntity) throws DAOException {

		this.update(groupBuyDefMerchantEntity);

	}

	@Override
	public void deleteGroupBuy(GroupBuyDefMerchantEntity groupBuyDefMerchantEntity) throws DAOException {

		this.delete(groupBuyDefMerchantEntity);

	}

	@Override
	public GroupBuyDefMerchantEntity getGroupBuyDefMerchantByUuid(String uuid) throws DAOException {
		GroupBuyDefMerchantEntity groupBuyDefMerchantEntity = null;
		try {
			groupBuyDefMerchantEntity = (GroupBuyDefMerchantEntity) em.createQuery(
					"select b from GroupBuyDefMerchantEntity b where  b.groupBuyDefMerchantUuid = :UUID and b.isDeleted=:isDeleted",
					GroupBuyDefMerchantEntity.class).setParameter("UUID", uuid).setParameter("isDeleted", Boolean.FALSE)
					.getSingleResult();
		} catch (NoResultException e) {
			logger.info("No record found for defMerchant : " + uuid);
		}
		return groupBuyDefMerchantEntity;
	}
}
